<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-accountAddress-edit"
			th:object="${accountAddress}">
			<input id="id" name="id" th:field="*{id}" type="hidden">
			<div class="form-group">
				<label class="col-sm-3 control-label">钱包地址：</label>
				<div class="col-sm-8">
					<input id="walletAddress" name="walletAddress" th:field="*{walletAddress}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">余额：</label>
				<div class="col-sm-5">
					<input id="walletBalance" name="walletBalance" th:field="*{walletBalance}" class="form-control" type="text">
				</div>
				<div class="col-sm-3">
					<a class="btn btn-success" onclick="getNodeWallet();"><i class="fa fa-search"></i>&nbsp;查询底层余额</a>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">节点余额：</label>
				<div class="col-sm-5">
					<input id="nodeWalletBalance" name="nodeWalletBalance" class="form-control" type="text">
				</div>
				<div class="col-sm-3">
					<a class="btn btn-primary btn-rounded btn-sm" onclick="updateWalletBalance();"><i class="fa  fa-edit"></i>&nbsp;更新余额</a>
				</div>
			</div>
		</form>
	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript">
		var prefix = ctx + "manager/accountAddress";
		//查询底层余额
		function getNodeWallet() {
			$.ajax({
				type : "GET",
				url : prefix + "/getAddressBalance/"+ $("#walletAddress").val(),
				dataType : "json",
				success : function(data) {
					if (data.code == 0) {
						$("#nodeWalletBalance").val(data.msg);
					} else {
						$.modal.alertWarning("查询底层金额失败");
					}
				},
				error : function(jqXHR) {
					$.modal.alertWarning("查询底层金额异常");
				}
			});

		}

		//更新余额
		function updateWalletBalance() {
			$.ajax({
				type : "GET",
				url : prefix + "/updateAddressBalance/"+ $("#walletAddress").val()+"/"+$("#nodeWalletBalance").val(),
				dataType : "json",
				success : function(data) {
					if (data.code == 0) {
						$.modal.alertWarning("更新成功");
					} else {
						$.modal.alertWarning("更新失败");
					}
				},
				error : function(jqXHR) {
					$.modal.alertWarning("更新异常");
				}
			});

		}
	
	</script>
</body>
</html>
